//Nicccce
import React, {Component} from 'react';
import NavigationBar from '../../Common/NavigationBar/NavigationBar.jsx';
import WeUI from 'react-weui';
import {CSS} from '../styles/userInfo.css';


const {
    CellsTitle,
    Cells,
    Cell,
    CellHeader,
    CellBody,
    CellFooter,
    Label,
    FormCell,
    Select,
    Article,
    ActionSheet,
} = WeUI;
export default class UserInfoContainer extends Component {
    constructor(props) {
        super(props);
        this.LeftClick = this.LeftClick.bind(this);
        this.BasicClick = this.BasicClick.bind(this);
        this.QuiteClick = this.QuiteClick.bind(this);
        this.ResetClick = this.ResetClick.bind(this);
        this.hide = this.hide.bind(this);
        this.show = this.show.bind(this);
        this.logoutClick = this.logoutClick.bind(this);
        this.state = {
            auto_show: false,
            menus: [{
                label: '您确认要退出登录吗？',
                style: {color: "#888888", fontSize: "1.4rem", padding: "2rem"},
            }, {
                label: '确认退出',
                style: {color: "#E64340", fontSize: "1.8rem"},
                onClick: this.QuiteClick
            }],
            actions: [
                {
                    label: '取消',
                    onClick: this.hide
                }
            ]
        };
    }

    logoutClick(){
        this.setState({
            auto_show: true,
        })
    }


    show() {
        this.setState({
            auto_show: true,
        })
    }

    hide() {
        this.setState({
            auto_show: false,
        })
    }

    componentWillMount() {
    }

    LeftClick() {
    }
    BasicClick(){
        location.hash = "/SetName?from=UserInfo";
    }

    ResetClick() {
        location.hash = "/ResetPassword";
    }

    QuiteClick() {
        //接口
        fetch(getHost() + "/user/logout", {
            method: 'POST',
            credentials: 'include'}).then(response => response.json())
            .then(d => {
                if (d.success) {
                    location.hash = "/Login";
                } else {
                    this.showWarn("网络出现了点问题");
                }
            });
    }


    render() {
        return (
            <div>
                <NavigationBar Title="个人信息" LeftBar="true" LeftTitle="返回"
                               LeftIconSrc="/iot-meeting/assets/images/common/nav_back_icon.png" LeftClick={this.LeftClick}/>
                <CellsTitle className="title_text">个人信息</CellsTitle>
                <Cells>
                    <Cell access onClick={this.BasicClick}>
                        <CellBody>
                            基础资料
                        </CellBody>
                        <CellFooter/>
                    </Cell>
                    <Cell access onClick={this.ResetClick}>
                        <CellBody>
                            重设密码
                        </CellBody>
                        <CellFooter/>
                    </Cell>
                    <Cell access onClick={this.logoutClick}>
                        <CellBody>
                            退出登录
                        </CellBody>
                        <CellFooter/>
                    </Cell>
                </Cells>
                <ActionSheet
                    menus={this.state.menus}
                    actions={this.state.actions}
                    show={this.state.auto_show}
                    onRequestClose={this.hide}
                />
            </div>
        )
    }


}
